#!/bin/bash
echo "hello world................."

your_name="hello.com"
for x in `ls ./`; do
 echo ${x}
done


myUrl="http://www.runoob.com"
unset myUrl
echo $PATH


str="this is a string"
echo ${str}

your_name='runoob'
str="Hello, I know you are \"$your_name\"! \n"
echo -e ${str}


your_name="runoob"

echo "==========1=========="
# 使用双引号拼接
greeting="hello, "${your_name}" !"

greeting_1="hello, ${your_name} !"

echo ${greeting}
echo ${greeting_1}

echo "==========2=========="
# 使用单引号拼接
greeting_2='hello, '${your_name}' !'
greeting_3='hello, ${your_name} !'
echo ${greeting_2}
echo ${greeting_3}



echo "==========string operation=========="
# 使用单引号拼接
greeting_2='hello, '${your_name}' !'
string="ab's"
echo ${#string} #输出 4

string="runoob is a great site"
echo ${string:1:4} # 输出 unoo


string="runoob is a great site"
echo `expr index "$string" io`  # 输出 4

echo "==========array operation=========="

array_name=(value0 value1 value2 value3)
array_name[4]="value4"
echo ${array_name[*]}
echo ${array_name[@]}
echo ${array_name[4]}


# 取得数组元素的个数
echo ${#array_name[@]}
# 或者
echo ${#array_name[*]}
# 取得数组单个元素的长度
echo ${#array_name[4]}

#多行注释
:<<EOF
注释内容...
注释内容...
注释内容...
EOF

echo "Shell 传递参数实例！";
echo "$0";
echo "first args: $1";
echo "$$";
echo "$!";
echo "$@";

if [[ -n "$1" ]]; then
    echo "has first args"
else
    echo "has not first args"
fi

echo "===============运算符999999==============="
a=10
b=20

val=`expr ${a} + ${b}`
echo "a + b : $val"

val=`expr ${a} - ${b}`
echo "a - b : $val"

val=`expr ${a} \* ${b}`
echo "a * b : $val"

val=`expr ${b} / ${a}`
echo "b / a : $val"

val=`expr ${b} % ${a}`
echo "b % a : $val"

if [[ ${a} == ${b} ]]
then
   echo "a == b"
fi
if [[ ${a} != ${b} ]]
then
   echo "a != b"
fi

a=10
b=20

if [[ ${a} != ${b} ]]
then
   echo "$a != $b : a 不等于 b"
else
   echo "$a == $b: a 等于 b"
fi
if [[ ${a} -lt 100 && ${b} -gt 15 ]]
then
   echo "$a 小于 100 且 $b 大于 15 : 返回 true"
else
   echo "$a 小于 100 且 $b 大于 15 : 返回 false"
fi
if [[ ${a} -lt 100 || ${b} -gt 100 ]]
then
   echo "$a 小于 100 或 $b 大于 100 : 返回 true"
else
   echo "$a 小于 100 或 $b 大于 100 : 返回 false"
fi
if [[ ${a} -lt 5 || ${b} -gt 100 ]]
then
   echo "$a 小于 5 或 $b 大于 100 : 返回 true"
else
   echo "$a 小于 5 或 $b 大于 100 : 返回 false"
fi

echo "==========运算符==========="
a="abc"
b="efg"

if [[ ${a} = ${b} ]]
then
   echo "$a = $b : a 等于 b"
else
   echo "$a = $b: a 不等于 b"
fi
if [[ ${a} != ${b} ]]
then
   echo "$a != $b : a 不等于 b"
else
   echo "$a != $b: a 等于 b"
fi
if [[ -z ${a} ]]
then
   echo "-z $a : 字符串长度为 0"
else
   echo "-z $a : 字符串长度不为 0"
fi
if [[ -n "$a" ]]
then
   echo "-n $a : 字符串长度不为 0"
else
   echo "-n $a : 字符串长度为 0"
fi
if [[ ${a} ]]
then
   echo "$a : 字符串不为空"
else
   echo "$a : 字符串为空"
fi